package xFGE.net
{
	import flash.events.Event;
	
	import xFGE.FGE;
	import xFGE.event.InQueueEvent;
	
	public class NetConnectionManager
	{
		private var _connecters:Array = new Array();
		
		public function NetConnectionManager()
		{
			
		}
		
		public function getConnecterByIdx(idx:int):IConnection
		{
			return _connecters[idx].connecter;
		}
		public function getConnecterByName(name:String):IConnection
		{
			for(var i:int=0;i<_connecters.length;i++)
			{
				if(name == _connecters[i].name)
				{
					return _connecters[i].connecter;
				}
			}
			return null;
		}
		public function pushConnecter(name:String,cter:IConnection):void
		{
			cter.add_onConnection_Listener(game_onConnection);
			_connecters.push({name:name,connecter:cter});
		}
		
		public function game_onConnection(event:Event):void
		{
			var dataObj:Object = new Object();
			dataObj.cmd = "game_on_connect";
			dataObj.rip = 0;
			parse(dataObj);
		}
		private function parse(dataObj:Object):void
		{
			try
			{
				var e:InQueueEvent = new InQueueEvent(dataObj.cmd);
				e._eventObject = dataObj;
				e._rip = dataObj.rip;
				xFGE.FGE.GetInstance().eventQueue.pushQueue(e);
			}
			catch(e:Error)
			{
				trace("BGameConnection.parse: "+e);
			}
		}
	}//end NetConnectionManager
}